<?php 
/**
 * 前台公共数据显示控制器
 * @author 杨帆
 */
class CommonController extends Controller{
    /**
     * 默认显示模板
     */
    public function commonShow(){
       $this->cateData(); 
       $this->hotSearch();
    }
    
    /**
    *头部顶级分类
    */
    public function cateData(){
         //显示头部类型列表
        $cataData = M('class')->where('is_nav=1')->order('cid')->all();
        foreach ($cataData as $k => $v) {
            $cataData[$k]['son'] = K('Goods')->where("class_cid={$v['cid']}")->limit(2)->all();
        }
        $this->assign('cataData',$cataData);
    }
    
    /**
    * 热点搜索数据
    */
    public function hotSearch(){
        //显示热点搜索数据
        $hotSearch = M('class')->where('is_nav=2')->order('cid')->all();
        $this->assign('hotSearch',$hotSearch);
    }
    
    
    /**
     * 处理图片地址，最终变为小中大图的地址
     */
    public function getPic($picArr){
        $temp = array();
        foreach ($picArr as $v) {
            //获取图片文件的类型；strrchr：查找指定字符在字符串中的最后一次出现；
            //Upload/Content/shop/15/08/55221440643622.jpg，$type=.jpg
            $type = strrchr($v, '.');
            //在$v中寻找$type,并将其替换为'_small' . $type，在压入$temp的数组中；
            $temp['small'][] = str_replace($type, '_small' . $type, $v);
            $temp['mid'][] = str_replace($type, '_mid' . $type, $v);
            $temp['big'][] = str_replace($type, '_big' . $type, $v);
        }
        return $temp;
    }
 }